<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    div {
      width: 800px;
      height: 400px;
    }
  </style>
  <body>
    <div></div>
  </body>
  <script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.1.2/echarts.js"></script>
  <script>
    // 基于准备好的dom，初始化echarts实例
    let dom = document.querySelector("div");
    //创建实例
    let myCharts = echarts.init(dom);
    //数据集,必须是二维数组
    let data = [
        ['衣服',10,22,'x',13],
        ['直播',12,55,'y',63],
        ['游戏',16,34,'z',20],
        ['电影',19,10,'t',25]
    ]
    // 使用刚指定的配置项和数据显示图表。
    myCharts.setOption({
      dataset:{
        source:data
      },
      title: {
        text: "数据可视化",
        subtext: "echarts基本使用",
        //主标题颜色
        textStyle: {
          color: "cyan",
        },
        //标题位置
        left: "center",
      },
      xAxis: {
        data: ["衣服", "直播", "游戏", "电影"],
      },
      yAxis: {
        //y轴的线
        axisLine: {
          show: true,
        },
        //y轴刻度
        axisTick: {
          show: true,
        },
      },
      //想要设置什么类型的图表，可以设置多个
      series: [
        {
          type: "bar",
          color: "red",
          encode:{
              y:1
          }
        },
        {
          type: "line",
          color: "green",
          encode:{
              y:2
          }
        },
        {
          type: "pie",
          encode:{
              //饼图的属性名称
              itemName:3,
              //饼图的属性值
              value:4
          },
          width:150,
          height:150,
          left:250,
          top:200,
          radius:25
        },
      ],
    });
  </script>
</html>
